package com.project.estate.commons.config;

import java.util.UUID;
import java.security.MessageDigest;
import java.math.BigInteger;

public class NumericUUIDGenerator {

    // 方法1：基于位运算
    public static long getNumericUUID() {
        UUID uuid = UUID.randomUUID();
        return Math.abs(uuid.getMostSignificantBits() ^ uuid.getLeastSignificantBits());
    }

    // 方法2：哈希转换
    public static String getHashedNumericUUID() throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(UUID.randomUUID().toString().getBytes());
        return new BigInteger(1, md.digest()).toString();
    }

    // 方法3：6位纯数字
    public static String getSixDigitUUID() {
        String hex = UUID.randomUUID().toString().replace("-", "").substring(0, 6);
        return String.format("%06d", Integer.parseInt(hex, 16) % 1000000);
    }

    public static void main(String[] args) throws Exception {
        System.out.println("位运算结果: " + getNumericUUID());
        System.out.println("哈希转换结果: " + getHashedNumericUUID());
        System.out.println("6位纯数字: " + getSixDigitUUID());
    }
}

